package com.elise;

import java.text.DecimalFormat;
import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class EtimeListAdapter extends BaseAdapter {
		
	private ArrayList<Etime> items;
	private Context context;
	
	private static DecimalFormat df = new DecimalFormat("00");
	
	public EtimeListAdapter(Context context, ArrayList<Etime> items) {
		this.items = items;
		this.context = context;
		
		
	}

	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int arg0) {
		return items.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		View view = convertView;
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(R.layout.today_list_item, parent, false);
		}
		
		TextView pos = (TextView) view.findViewById(R.id.today_list_item_position);
		TextView t_in = (TextView) view.findViewById(R.id.today_list_item_time_in);
		TextView mins = (TextView) view.findViewById(R.id.today_list_item_minutes);
		TextView amount = (TextView) view.findViewById(R.id.today_list_item_amount);
		
		pos.setText(df.format(position +1));
		t_in.setText(Etime.timeFormat.format(items.get(position).getTime_in()));
		mins.setText(Etime.timeFormat.format(items.get(position).getMinutes()));
		amount.setText(Etime.currencyFormat.format(items.get(position).getAmount()));
	
		if (position%2 == 0)
			view.setBackgroundColor(context.getResources().getColor(R.color.today_list_item_color1));
		else
			view.setBackgroundColor(context.getResources().getColor(R.color.today_list_item_color2));
		
		return view;
	}
}
